﻿using System;

namespace LdCms.Plugins.Map.Tencent
{
    using LdCms.Common.Json;
    using LdCms.Common.Logs;
    using LdCms.Common.Net;
    using LdCms.Common.Security;
    using LdCms.Common.Web;
    using LdCms.Plugins.Map.Tencent.Common;
    using LdCms.Plugins.Map.Tencent.Models;

    /// <summary>
    /// 腾讯地图 WebService API
    /// 注：已完成
    /// 功能如下：
    ///     01、地点搜索
    ///     02、关键词输入提示
    ///     03、逆地址解析(坐标位置描述)
    ///     04、地址解析(地址转坐标)
    ///     05、行政区划
    ///     06、路线规划服务 new
    ///     07、距离计算（一对多）
    ///     08、距离矩阵（多对多） new
    ///     09、坐标转换
    ///     10、IP定位
    /// </summary>
    public class TencentMapHelper: WebServiceAPIUrl
    {
        public string Key { get; set; }
        public string SK { get; set; }
        public TencentMapHelper() { }
        public TencentMapHelper(string key, string sk)
        {
            this.Key = key;
            this.SK = sk;
        }
        /// <summary>
        /// GET请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private string GetUrl(string url)
        {
            try
            {
                string str = GeneralCodeHelper.GetRandomInt(8);
                string result = HttpHelper.GetToUrl(url);
                LogsManager.LogPath = string.Empty;
                LogsManager.logFielPrefix = string.Empty;
                LogsManager.WriteLog(LogsFile.Debug, string.Format("[{0}]-腾讯地图WebServiceAPI--开结--", str));
                LogsManager.WriteLog(LogsFile.Debug, string.Format("[{0}]-IP：{1}", str, Net.Ip));
                LogsManager.WriteLog(LogsFile.Debug, string.Format("[{0}]-地址：{1}", str, url));
                LogsManager.WriteLog(LogsFile.Debug, string.Format("[{0}]-结果：{1}",str, result.MiniClear()));
                LogsManager.WriteLog(LogsFile.Debug, string.Format("[{0}]-腾讯地图WebServiceAPI--结束--", str));
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        #region 地点搜索
        /// <summary>
        /// 创建地点搜索URL
        /// </summary>
        /// <param name="placeSearch"></param>
        /// <returns></returns>
        public string CreatePlaceSearchUrl(PlaceSearch placeSearch)
        {
            try
            {
                //placeSearch.key = Key;
                string url = placeSearchUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(placeSearch);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 地点搜索
        /// </summary>
        /// <param name="placeSearch"></param>
        /// <returns></returns>
        public string GetPlaceSearch(PlaceSearch placeSearch)
        {
            try
            {
                string url = CreatePlaceSearchUrl(placeSearch);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 地点搜索
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public PlaceSearchResult GetPlaceSearchPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<PlaceSearchResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 地点搜索
        /// </summary>
        /// <param name="placeSearch"></param>
        /// <returns></returns>
        public PlaceSearchResult GetPlaceSearchPro(PlaceSearch placeSearch)
        {
            try
            {
                string result = GetPlaceSearch(placeSearch);
                return result.ToObject<PlaceSearchResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

        #region 关建字搜索
        /// <summary>
        /// 关建字搜索
        /// </summary>
        /// <param name="placeSuggestion"></param>
        /// <returns></returns>
        public string CreatePlaceSuggestionUrl(PlaceSuggestion placeSuggestion)
        {
            try
            {
                //placeSuggestion.key = Key;
                string url = placeSuggestionUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(placeSuggestion);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 关建字搜索
        /// </summary>
        /// <param name="placeSuggestion"></param>
        /// <returns></returns>
        public string GetPlaceSuggestion(PlaceSuggestion placeSuggestion)
        {
            try
            {
                string url = CreatePlaceSuggestionUrl(placeSuggestion);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 关建字搜索
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public PlaceSuggestionResult GetPlaceSuggestionPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<PlaceSuggestionResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 关建字搜索
        /// </summary>
        /// <param name="placeSuggestion"></param>
        /// <returns></returns>
        public PlaceSuggestionResult GetPlaceSuggestionPro(PlaceSuggestion placeSuggestion)
        {
            try
            {
                string result = GetPlaceSuggestion(placeSuggestion);
                return result.ToObject<PlaceSuggestionResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

        #region 逆地址解析(坐标位置描述)
        /// <summary>
        /// 逆地址解析(坐标位置描述)
        /// </summary>
        /// <param name="geocoder"></param>
        /// <returns></returns>
        public string CreateGeocoderLocationUrl(GeocoderLocation geocoder)
        {
            try
            {
                //geocoder.key = Key;
                string url = geocoderUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(geocoder);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 逆地址解析(坐标位置描述)
        /// </summary>
        /// <param name="geocoder"></param>
        /// <returns></returns>
        public string GetGeocoderLocation(GeocoderLocation geocoder)
        {
            try
            {
                string url = CreateGeocoderLocationUrl(geocoder);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 逆地址解析(坐标位置描述)
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public GeocoderLocationResult GetGeocoderLocationPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<GeocoderLocationResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 逆地址解析(坐标位置描述)
        /// </summary>
        /// <param name="geocoder"></param>
        /// <returns></returns>
        public GeocoderLocationResult GetGeocoderLocationPro(GeocoderLocation geocoder)
        {
            try
            {
                string result = GetGeocoderLocation(geocoder);
                return result.ToObject<GeocoderLocationResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

        #region 地址解析(地址转坐标)
        /// <summary>
        /// 地址解析(地址转坐标)
        /// </summary>
        /// <param name="geocoder"></param>
        /// <returns></returns>
        public string CreateGeocoderAddressUrl(GeocoderAddress geocoder)
        {
            try
            {
                //geocoder.key = Key;
                string url = geocoderUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(geocoder);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 地址解析(地址转坐标)
        /// </summary>
        /// <param name="geocoder"></param>
        /// <returns></returns>
        public string GetGeocoderAddress(GeocoderAddress geocoder)
        {
            try
            {
                string url = CreateGeocoderAddressUrl(geocoder);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 地址解析(地址转坐标)
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public GeocoderAddressResult GetGeocoderAddressPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<GeocoderAddressResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 地址解析(地址转坐标)
        /// </summary>
        /// <param name="geocoder"></param>
        /// <returns></returns>
        public GeocoderAddressResult GetGeocoderAddressPro(GeocoderAddress geocoder)
        {
            try
            {
                string result = GetGeocoderAddress(geocoder);
                return result.ToObject<GeocoderAddressResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

        #region 行政区划
        /// <summary>
        /// 行政区划 - 全部
        /// </summary>
        /// <param name="districtList"></param>
        /// <returns></returns>
        public string CreateDistrictListUrl(DistrictList districtList)
        {
            try
            {
                //districtList.key = Key;
                string url = districtListUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(districtList);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划 - 指定行政区划的子级行政区划
        /// </summary>
        /// <param name="districtGetchildren"></param>
        /// <returns></returns>
        public string CreateDistrictGetchildrenUrl(DistrictGetchildren districtGetchildren)
        {
            try
            {
                //districtGetchildren.key = Key;
                string url = districtGetchildrenUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(districtGetchildren);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划 - 关键词搜索行政区划
        /// </summary>
        /// <param name="districtSearch"></param>
        /// <returns></returns>
        public string CreateDistrictSearchUrl(DistrictSearch districtSearch)
        {
            try
            {
                //districtSearch.key = Key;
                string url = districtSearchUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(districtSearch);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划 - 全部
        /// </summary>
        /// <param name="districtList"></param>
        /// <returns></returns>
        public string GetDistrictList(DistrictList districtList)
        {
            try
            {
                string url = CreateDistrictListUrl(districtList);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划 - 指定行政区划的子级行政区划
        /// </summary>
        /// <param name="districtGetchildren"></param>
        /// <returns></returns>
        public string GetDistrictGetchildren(DistrictGetchildren districtGetchildren)
        {
            try
            {
                string url = CreateDistrictGetchildrenUrl(districtGetchildren);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划 - 关键词搜索行政区划
        /// </summary>
        /// <param name="districtSearch"></param>
        /// <returns></returns>
        public string GetDistrictSearch(DistrictSearch districtSearch)
        {
            try
            {
                string url = CreateDistrictSearchUrl(districtSearch);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public DistrictResult GetDistrictResultPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<DistrictResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划 - 全部
        /// </summary>
        /// <param name="districtList"></param>
        /// <returns></returns>
        public DistrictResult GetDistrictListPro(DistrictList districtList)
        {
            try
            {
                string result = GetDistrictList(districtList);
                return result.ToObject<DistrictResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划 - 指定行政区划的子级行政区划
        /// </summary>
        /// <param name="districtGetchildren"></param>
        /// <returns></returns>
        public DistrictResult GetDistrictGetchildrenPro(DistrictGetchildren districtGetchildren)
        {
            try
            {
                string result = GetDistrictGetchildren(districtGetchildren);
                return result.ToObject<DistrictResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 行政区划 - 关键词搜索行政区划
        /// </summary>
        /// <param name="districtSearch"></param>
        /// <returns></returns>
        public DistrictResult GetDistrictSearchPro(DistrictSearch districtSearch)
        {
            try
            {
                string result = GetDistrictSearch(districtSearch);
                return result.ToObject<DistrictResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

        #region 路线规划服务
        public string CreateDirectionDrivingUrl(DirectionDriving directionDriving)
        {
            try
            {
                //districtList.key = Key;
                string url = directionDrivingUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(directionDriving);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public string GetDirectionDriving(DirectionDriving directionDriving)
        {
            try
            {
                string url = CreateDirectionDrivingUrl(directionDriving);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public DirectionDrivingResult GetDirectionDrivingPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<DirectionDrivingResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public DirectionDrivingResult GetDirectionDrivingPro(DirectionDriving directionDriving)
        {
            try
            {
                string result = GetDirectionDriving(directionDriving);
                return result.ToObject<DirectionDrivingResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        public string CreateDirectionWalkingUrl(DirectionWalking directionWalking)
        {
            try
            {
                //districtList.key = Key;
                string url = directionWalkingUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(directionWalking);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public string GetDirectionWalking(DirectionWalking directionWalkin)
        {
            try
            {
                string url = CreateDirectionWalkingUrl(directionWalkin);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public DirectionWalkingResult GetDirectionWalkingPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<DirectionWalkingResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public DirectionWalkingResult GetDirectionWalkingPro(DirectionWalking directionWalkin)
        {
            try
            {
                string result = GetDirectionWalking(directionWalkin);
                return result.ToObject<DirectionWalkingResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        public string CreateDirectionBicyclingUrl(DirectionBicycling directionBicycling)
        {
            try
            {
                //districtList.key = Key;
                string url = directionBicyclingUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(directionBicycling);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public string GetDirectionBicycling(DirectionBicycling directionBicycling)
        {
            try
            {
                string url = CreateDirectionBicyclingUrl(directionBicycling);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public DirectionBicyclingResult GetDirectionBicyclingPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<DirectionBicyclingResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public DirectionBicyclingResult GetDirectionBicyclingPro(DirectionBicycling directionBicycling)
        {
            try
            {
                string result = GetDirectionBicycling(directionBicycling);
                return result.ToObject<DirectionBicyclingResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        public string CreateDirectionTransitUrl(DirectionTransit directionTransit)
        {
            try
            {
                //districtList.key = Key;
                string url = directionTransitUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(directionTransit);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public string GetDirectionTransit(DirectionTransit directionTransit)
        {
            try
            {
                string url = CreateDirectionTransitUrl(directionTransit);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public DirectionTransitResult GetDirectionTransitPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<DirectionTransitResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public DirectionTransitResult GetDirectionTransitPro(DirectionTransit directionTransit)
        {
            try
            {
                string result = GetDirectionTransit(directionTransit);
                return result.ToObject<DirectionTransitResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        #endregion

        #region 距离计算（一对多）
        /// <summary>
        /// 距离计算（一对多）
        /// </summary>
        /// <param name="distance"></param>
        /// <returns></returns>
        public string CreateDistanceUrl(Distance distance)
        {
            try
            {
                //distance.key = Key;
                string url = distanceUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(distance);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 距离计算（一对多）
        /// </summary>
        /// <param name="distance"></param>
        /// <returns></returns>
        public string GetDistance(Distance distance)
        {
            try
            {
                string url = CreateDistanceUrl(distance);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 距离计算（一对多）
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public DistanceResult GetDistancePro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<DistanceResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 距离计算（一对多）
        /// </summary>
        /// <param name="distance"></param>
        /// <returns></returns>
        public DistanceResult GetDistancePro(Distance distance)
        {
            try
            {
                string result = GetDistance(distance);
                return result.ToObject<DistanceResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

        #region 距离计算（多对多）
        /// <summary>
        /// 距离计算（多对多）
        /// </summary>
        /// <param name="distanceMatrix"></param>
        /// <returns></returns>
        public string CreateDistanceMatrixUrl(DistanceMatrix distanceMatrix)
        {
            try
            {
                //distanceMatrix.key = Key;
                string url = distanceMatrixUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(distanceMatrix);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 距离计算（多对多）
        /// </summary>
        /// <param name="distance"></param>
        /// <returns></returns>
        public string GetDistanceMatrix(DistanceMatrix distanceMatrix)
        {
            try
            {
                string url = CreateDistanceMatrixUrl(distanceMatrix);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 距离计算（多对多）
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public DistanceMatrixResult GetDistanceMatrixPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<DistanceMatrixResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 距离计算（多对多）
        /// </summary>
        /// <param name="distance"></param>
        /// <returns></returns>
        public DistanceMatrixResult GetDistanceMatrixPro(DistanceMatrix distanceMatrix)
        {
            try
            {
                string result = GetDistanceMatrix(distanceMatrix);
                return result.ToObject<DistanceMatrixResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        #endregion

        #region IP定位
        /// <summary>
        /// IP定位
        /// </summary>
        /// <param name="locationIp"></param>
        /// <returns></returns>
        public string CreateLocationIpUrl(LocationIp locationIp)
        {
            try
            {
                //locationIp.key = Key;
                string url = locationIpUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(locationIp);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// IP定位
        /// </summary>
        /// <param name="locationIp"></param>
        /// <returns></returns>
        public string GetLocationIp(LocationIp locationIp)
        {
            try
            {
                string url = CreateLocationIpUrl(locationIp);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// IP定位
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public LocationIpResult GetLocationIpPro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<LocationIpResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// IP定位
        /// </summary>
        /// <param name="locationIp"></param>
        /// <returns></returns>
        public LocationIpResult GetLocationIpPro(LocationIp locationIp)
        {
            try
            {
                string result = GetLocationIp(locationIp);
                return result.ToObject<LocationIpResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

        #region 坐标转换
        /// <summary>
        /// 坐标转换
        /// </summary>
        /// <param name="coordTranslate"></param>
        /// <returns></returns>
        public string CreateCoordTranslateUrl(CoordTranslate coordTranslate)
        {
            try
            {
                //coordTranslate.key = Key;
                string url = coordTranslateUrl;
                string path = new Uri(url).AbsolutePath;
                var sdParams = Utilities.EntityToSortedDictionary(coordTranslate);
                string sign = Utilities.GetSign(sdParams, path, SK);
                string urlParams = Utilities.SortedDictionaryToUrlParams(sdParams);
                return string.Format("{0}?{1}&sig={2}", url, urlParams, sign);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 坐标转换
        /// </summary>
        /// <param name="coordTranslate"></param>
        /// <returns></returns>
        public string GetCoordTranslate(CoordTranslate coordTranslate)
        {
            try
            {
                string url = CreateCoordTranslateUrl(coordTranslate);
                return GetUrl(url);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 坐标转换
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public CoordTranslateResult GetCoordTranslatePro(string url)
        {
            try
            {
                string result = GetUrl(url);
                return result.ToObject<CoordTranslateResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 坐标转换
        /// </summary>
        /// <param name="coordTranslate"></param>
        /// <returns></returns>
        public CoordTranslateResult GetCoordTranslatePro(CoordTranslate coordTranslate)
        {
            try
            {
                string result = GetCoordTranslate(coordTranslate);
                return result.ToObject<CoordTranslateResult>();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

    }


}
